{extend name="base/form" /}
{block name="title"} 首页 {/block}
<!-- Page Content -->
{block name="content"}
<form class="layui-form" action="{:url('addPost')}" method="post">
    <input type="hidden" name="id" value="{$data.id}">

    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-block">
            <select lay-filter="aihao" name="pid" id='pid'>
                <option value="0">顶级菜单 </option>
                {volist name='auth' id='vo'}
                    <option {eq name="data.pid" value="$vo.id"} selected {/eq}  value="{$vo.id}">{$vo.level-1|str_repeat='丨--',###}{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-block">
            <input type="text"  name="title" value="{$data.title|default=''}" lay-verify="required" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单地址</label>
        <div class="layui-input-block">
            <input type="text"  name="name" value="{$data.name|default=''}"  autocomplete="off" placeholder="请输入菜单地址" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" {eq name="data.status" value="1"}  checked  {/eq} value="1" lay-skin="switch" lay-text="显示|隐藏">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button style="margin-left: 20%" class="layui-btn" lay-submit="" lay-filter="addSubmit">提交</button>
            <button id="reset" type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<!-- /Page Content -->
{/block}
{block name="js"}
<script>
    //Demo
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        //当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        //监听提交
        form.on('submit(addSubmit)', function(data){
            console.log(data.field)
            $.ajax({
                url:"{:url('editPost')}",
                type:'post',
                data:data.field,
                success:function(e){
                    if(e.code == 1){
                        layer.msg(e.msg,{icon:6,time:2000},function (){
                            parent.layer.close(index); //再执行关闭
                            window.location.reload()
                        })
                    }else{
                        layer.msg(e.msg,{icon:5,time:2000},function (){
                            parent.layer.close(index); //再执行关闭
                            window.location.reload()
                        })
                    }

                }
            });
            return false;
        });
    });
</script>
{/block}